import { sessionSave, sessionRead, sessionRemove } from "/@/lib/sessionstorage"
import { localSave, localRead, localRemove } from "/@/lib/localstorage"
import { STORAGE_PREFIX, TOKEN_VALUE } from "../constants/keys";

/** 本地存储 KEY **/

// App信息
const APP_INFO = STORAGE_PREFIX + 'app_info';
export const getAppInfo = () => sessionRead(APP_INFO) || {};
export const setAppInfo = (value) => sessionSave(APP_INFO, JSON.stringify(value));
export const removeAppInfo = () => sessionRemove(APP_INFO);

// token
const TOKEN = STORAGE_PREFIX + 'token';
export const getToken = () => (import.meta.env.VITE_APP_TEST_MODE != 'false' ? TOKEN_VALUE : sessionRead(TOKEN));
export const setToken = (value) => sessionSave(TOKEN, value);
export const removeToken = () => sessionRemove(TOKEN);

// 菜单
const MENU_LIST = STORAGE_PREFIX + 'menu_list';
export const getMenuList = () => JSON.parse(sessionRead(MENU_LIST)) || [];
export const setMenuList = (value) => sessionSave(MENU_LIST, JSON.stringify(value));
export const removeMenuList = () => sessionRemove(MENU_LIST);

// 菜单按钮
const MENU_OPERATIONS = STORAGE_PREFIX + 'menu_operations';
export const getMenuOperations = () => JSON.parse(sessionRead(MENU_OPERATIONS)) || {};
export const setMenuOperations = (value) => sessionSave(MENU_OPERATIONS, JSON.stringify(value));
export const removeMenuOperations = () => sessionRemove(MENU_OPERATIONS);

// 用户信息
const USER_INFO = STORAGE_PREFIX + 'user_info';
export const getUserInfo = () => JSON.parse(sessionRead(USER_INFO)) || {};
export const setUserInfo = (value) => sessionSave(USER_INFO, JSON.stringify(value));
export const removeUserInfo = () => sessionRemove(USER_INFO);

// 本系统当前语言
const LANGUAGE = STORAGE_PREFIX + 'language';
export const getLanguage = () => sessionRead(LANGUAGE) || 'zh-CN';
export const setLanguage = (value) => sessionSave(LANGUAGE, value);
export const removeLanguage = () => sessionRemove(LANGUAGE);

// 代办消息
const MESSAGE = STORAGE_PREFIX + 'message';
export const getMessage = () => sessionRead(MESSAGE) || 'zh-CN';
export const setMessage = (value) => sessionSave(MESSAGE, value);
export const removeMessage = () => sessionRemove(MESSAGE);

// 系统配置信息
const APPCONFIG = STORAGE_PREFIX + 'appconfig';
export const getAppConfig = () => localRead(APPCONFIG) || 'zh-CN';
export const setAppConfig = (value) => localSave(APPCONFIG, value);
export const removeAppConfig = () => localRemove(APPCONFIG);